import 'dart:convert';


import 'package:du_application/http/HttpUtil.dart';
import 'package:du_application/http/Options.dart';
import 'package:du_application/model/AffairDetailModel.dart';
import 'package:du_application/model/FolloewModel.dart';
import 'package:du_application/provide/AuthProvider.dart';
import 'package:flutter/material.dart';
import 'package:provide/provide.dart';
import 'package:shared_preferences/shared_preferences.dart';

class AffairDetailProvider with ChangeNotifier {
   AffairDetailModel affairDetailModel;
     Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
  getAffair(context,id) async {
     return await _prefs.then((ins) async{
    Options options =  Options(Provide.value<AuthProvider>(context).token);
    return await HttpUtil.getInstance().get("/affair/index",data: {
      "id":id,
    },options:options.options).then((data) {
      // LogUtil.e(data);
      affairDetailModel=AffairDetailModel.fromJson(json.decode(data));
        notifyListeners();
       return affairDetailModel;
     });
    });
  }
    follow(context,id) async {
     return await _prefs.then((ins) async{
    Options options =  Options(Provide.value<AuthProvider>(context).token);
    return await HttpUtil.getInstance().get("/friend/follow",data: {
      "id":id,
    },options:options.options).then((data) {
      // LogUtil.e(data);
     FolloewModel folloewModel= FolloewModel.fromJson(json.decode(data));
     affairDetailModel.data.follow= folloewModel.data;
             notifyListeners();
     
     });
    });
  }
}